<template>
	
 	<div class="layui-layout layui-layout-admin" >
 	  <div class="adminnav1">	
        <Pagetop></Pagetop>
      </div>
      <div class="adminnav2">	
       	<Secondnav urlname="order"></Secondnav>
      </div>
      
      <!-- 主体内容 -->
      <div class="layui-body kedou-admin" id="LAY_app_body app">
	    <div class="layadmin-tabsbody-item layui-show">
	    	<div class="pagelist">
	    		<div class="layui-card-body">
		      		<fieldset class="layui-elem-field layui-field-title">
					  <legend>消费订单管理</legend>
					</fieldset>
		      	</div>
	    		<div class="pagetop">
	    			<Search :seadate="searchArr"></Search>			    	
		        </div>
		        <div class="layui-card-body">
		        	<div class="buttop" id="buttop">
					    <button type="button" class="layui-btn" @click="getData(0)">已付款</button>
					    <button type="button" class="layui-btn  layui-btn-primary" @click="getData(1)">已消费</button>
					    <button type="button" class="layui-btn  layui-btn-primary" @click="getData(2)">已取消</button>					    					    					 
		        	</div>
			        <Tables :fdate="pdate" :result="res" height="430" :totalCount="totalRows" :pageNumber="curindex" :fbtn="btn"></Tables>      			     
		        </div>		      
	        </div>
	    </div>
	  </div>  
	     
	</div>
</template>
<script>	
	import Pagetop from '../common/pagetop.vue'
	import Secondnav from '../common/secondnav.vue'
	import Tables from '../common/tables.vue'
	import Search from '../common/search.vue'
	export default {
	  name: 'xforder',
	  components: {Pagetop,Secondnav,Tables,Search},	  
	  data () {
	    return {
	        pdate:[], //表头  	
	    	res:"", //内容
	    	totalRows:"",//总数量
	    	curindex:1, //页数
	    	btn:[],//按钮
	    	searchArr:[],//搜索
	    	isShow:false, 
	    	seapram:'',
	    	isclick:0,
	    	shopId:localStorage.getItem("shopId"),
	    }
	  },
	  mounted(){ 	
	  	this.getdate();
     	this.getsearch();
	  },
	  methods: {	 	  
		getdate:function(){     	
    	var _this=this;
    	if(_this.isclick==0){
    		var status='SUCCESSFUL'; //已付款		
    	}else if(_this.isclick==1){
    		var status='UNVERIFIED'; //已消费  	
    	}else if(_this.isclick==2){
    		var status='CANCEL';//已取消    	
    	}
    	var url="/verify/bapi/v1.9/consumption-order/consumptionPay"    	
    	if(_this.seapram){
    		var dates={
	    		 size:pageSize,
	    		 page:_this.curindex,
	    		 'shopId.equals':_this.shopId,
	    		 'status.equals':status,
		       //  sort:'createAt,DESC',
		         //'status.equals':'ENABLE'
	    	}
    		var res=_this.seapram;
    		for(var i=0;i<res.length;i++){
    			//dates[res[i].key]=res[i].val;
    			dates[res[i].key+'.equals']=res[i].val;
    		}
    		
    	}else{
	    	var dates={
	    		 size:pageSize,
	    		 page:_this.curindex,
	    		 'shopId.equals':_this.shopId,
	    		 'status.equals':status,
		        // sort:'createAt,DESC',
		         //'status.equals':'ENABLE'
	    	}
        }  		    	
        //	alert(url+"//"+JSON.stringify(dates))
      	ajaxRequest(url,'GET','json',dates,function(ret,err){
      		//alert(url+"//"+JSON.stringify(ret))
	  		var arr=[];  		
		  	arr[0]=[ 
		  	   {field: 'id', title: 'ID',}
		      ,{field: 'consumeOrder', title: '订单号',width:'200',templet:function(d){return d.consumeOrder.serialno}}		     	     			      
		      ,{field: 'project', title: '商品图片',width:'120',templet:'<div><img src="{{d.project.logo}}" style="display: inline-block; height: 100%;"></div>'}	      	
		      ,{field: 'project', title: '商品名称',width:'150',templet:function(d){return d.project.name}}		     
		      ,{field: 'createAt', title: '时间',width:'150',templet:function(d){return FormatDate(d.createAt)}}		     	      
		      ,{field: 'totalAmount', title: '消费金额（元）',width:'150',templet:function(d){return d.totalAmount/100}}
		      ,{field: 'payDetail', title: '支付方式',width:'150',templet:function(d){
		      	 if(d.payDetail){
			      	 if(d.payDetail.channelId=='-1'||d.payDetail.channelId=='10')return '余额支付'
			         else if(d.payDetail.channelId=='113')return '支付宝app支付'
			         else if(d.payDetail.channelId=='123')return '微信app支付'
			         else if(d.payDetail.channelId=='125')return '微信小程序'	
			         else if(d.payDetail.channelId=='12')return 'UC支付'	
			         else if(d.payDetail.channelId=='13')return 'WUC支付'	
			     }    
		      }}
		      ,{field: 'verifyCode', title: '验证码',width:'200',}
		      ,{field: 'verifyStatus', title: '状态',width:'150',templet:function(d){
		      	 if(d.verifyStatus=='UNVERIFIED')return '未验证'
		      	 else if(d.verifyStatus=='VERIFY_SUCCESS')return '验证成功'
		      	 else return'已取消'	         		        
		        }}
		      ,{field: 'right',title: '操作', width:'160', fixed:'right',templet:function(d){
		      	
		      	 if(status=='SUCCESSFUL'){
		            var str='<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="code">验证</a>';
		         }else{
		         	var str='';		         	
		         }
		         if(status!='CANCEL'){
			         if(d.freezeStatus=='CONSUME'){
			            var str1='<a class="layui-btn layui-btn-xs " lay-event="edit">冻结</a>';
			         }else if(d.freezeStatus=='AFREEZED'){
			         	var str1='<a class="layui-btn layui-btn-xs " lay-event="edit">冻结</a>';
			         }else if(d.freezeStatus=='FREEZED'){
			         	var str1='<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="upper">解冻</a>';
			         }else{
			         	var str1='';	
			         }
		         }else{
		         	var str1='';
		         }
		         var str2='<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="detail">详情</a>';
		         return str+str1+str2;
		      }}
		    ];
//		    var res1=[]
//		    res1=[{a:'1',b:'小m'},{a:'1',b:'小m'},]		    		   		  	
		  	_this.pdate=arr;		  	
		  	_this.res=ret.data.list; //res1; 		  
		  	_this.totalRows=ret.data.totalRows;
		  	_this.curindex=ret.data.pageNumber+1;		  	
	    })	
    },     
     getsearch:function(){
    	var arr=[
    		{field: 'id', title: '订单号',type: 'input'}     	
    	];
    	this.searchArr=arr;
   	
    },
    page:function(index,obj){
    	//alert(JSON,stringify(obj))
    	this.curindex=index;
    	this.getdate();
    	
    }, 
    sousuo:function(pram){
    	//alert(JSON.stringify(pram))
    	this.seapram=pram;
    	this.res='';
    	this.totalRows='';
    	this.curindex=1;
    	this.getdate();
    },    
    getData:function(is){
    	this.isclick=is;
    	this.getdate();
    	if(is==0){
    	  $('#buttop').find('.layui-btn:eq(0)').removeClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(1)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(2)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(3)').addClass('layui-btn-primary')
    	}else if(is==1){
    	  $('#buttop').find('.layui-btn:eq(1)').removeClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(0)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(2)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(3)').addClass('layui-btn-primary')  
    	}else if(is==2){
    	  $('#buttop').find('.layui-btn:eq(2)').removeClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(0)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(1)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(3)').addClass('layui-btn-primary')
    	}else if(is==3){
    	  $('#buttop').find('.layui-btn:eq(3)').removeClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(0)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(1)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(2)').addClass('layui-btn-primary')  
    	}        
	},
	addData:function(){     	
       // this.$router.push({name:'jfadd'})	
	},
	codeInfo:function(data){
		//this.$router.push({name:'jfadd',query:{'shopId':data.shopId,'commodityId':data.commodityId}})	   	
		var _this=this;
		var datas={
			verifyCode:data.verifyCode,
		}
		var url="/verify/bapi/v1.9/consumption-order/useVerifyCode"
	    ajaxRequest(url,'PUT','json',datas,function(ret,err){
	    	layer.msg('验码成功');
	    	var is=_this.isclick;
	    	setTimeout(function(){
			  	 _this.getData(is)
	        },1000)	    	
	    })
	},
    upperInfo:function(data){
    	//freezeStatus:冻结状态FREEZED ,解冻消费 AFREEZED,CONSUME未操作消费
    	var _this=this;		
		var id=data.id
		layer.confirm('是否确认解冻？', function(){
			var url="/verify/bapi/v1.9/consumption-order/freezeConsumption/"+id+"/AFREEZED"
		    ajaxRequest(url,'PUT','json',datas,function(ret,err){
		    	layer.msg('操作成功');
		    	var is=_this.isclick;
		    	setTimeout(function(){
				  	 _this.getData(is)
		        },1000)	    	
		    })
	    })
    },
    editInfo:function(data){
    	var _this=this;		
		var id=data.id
		layer.confirm('是否确认冻结？', function(){
			var url="/verify/bapi/v1.9/consumption-order/freezeConsumption/"+id+"/FREEZED"	
		    ajaxRequest(url,'PUT','json',datas,function(ret,err){
		    	layer.msg('操作成功');
		    	var is=_this.isclick;
		    	setTimeout(function(){
				  	 _this.getData(is)
		        },1000)	    	
		    })
	    })
    },
    detailInfo:function(data){
    	var _this = this;
		var datas={
			id:data.id,			
		}
		layer.open({
            type: 2
            ,title: '消费订单详情'
            ,shadeClose: false//点击遮罩关闭
            ,content:baseurl+'xfdetail'
            ,area: _this.screens() < 2 ? ['90%', '80%'] : ['650px', '550px']          
            ,success : function(layero, index){
		        var iframeWin = window[layero.find('iframe')[0]['name']];
		        iframeWin.getdates(datas);
	        },	      
        });
    },
	screens:function(){
		return screen();
	},	
  },
  updated:function(){
  	this.isShow = true;
	layui.use('form', function(){
	  var form = layui.form;
	  form.render();	 
	});
  },
}
</script>
<style scoped>
/**/
</style>
